require('page/common/header/index.js');
var _util = require('util/util.js');
var _catalog_service = require('service/catalog-service.js');

var listTemplate = require('./index.string');
var catalogList = {
    listData : {
        title           : '',
        headList        : [],
        productList     : {},
        itemList        : {}
    },
    productHeadList : [
        'Product Id',
        'Name'      
    ],
    itemHeadList    : [
        'Item Id'       ,
        'Product Id'    ,
        'description'   ,
        'List Price'    ,
        ' '
    ],
    init : function(){
        this.bindEvents();
        this.loadAccountInfo();
        return this;
    },
    bindEvents(){},
    loadAccountInfo : function(){
        var id = _util.getURLParam('id');
        var route = _util.getURLParam('route');

        var _this = this;

        if(route === 'product'){
            _catalog_service.getProductList(id,
                function(res){
                    _this.listData.headList = _this.productHeadList;
                    _this.listData.title             = id;
                    _this.listData.productList = res;
                    _this.listData.itemList = null;

                    var result = _util.renderHtml(listTemplate,{ListData:_this.listData});
                    $('#Catalog').html(result);

                },
                function(errMsg){
    
                }
            )
        }
        if(route === 'item'){
            _catalog_service.getItemList(id,
                function(res){
                    _this.listData.headList = _this.itemHeadList;
                    _this.listData.title             = id;
                    _this.listData.productList = null;
                    _this.listData.itemList = res;

                    var result = _util.renderHtml(listTemplate,{ListData:_this.listData});
                    console.log(result);
                    $('#Catalog').html(result);

                },
                function(errMsg){
    
                }
            )
           
        }
        
    }
};

module.exports = catalogList.init();